package com.village.friend.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.village.friend.dto.request.QuestionAddDto;
import com.village.friend.entity.UserQuestion;
import com.village.friend.mapper.UserQuestionMapper;
import com.village.friend.service.UserQuestionService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户反馈表 服务实现类
 * </p>
 *
 * @author yl
 * @since 2021-09-23
 */
@Service
public class UserQuestionServiceImpl extends ServiceImpl<UserQuestionMapper, UserQuestion> implements UserQuestionService {

    @Override
    public void add(Integer userId, QuestionAddDto param) {
        UserQuestion question = new UserQuestion();
        question.setQuestion(param.getQuestion());
        question.setUserId(userId);
        question.setContact(param.getContact());
        question.setImages(JSON.toJSONString(param.getImageList()));
        save(question);
    }

    @Override
    public void del(Integer userId, Integer id) {
        UserQuestion q = getById(id);
        if(q == null){
            throw new RuntimeException("要删除的问题不存在");
        }
        if(q.getUserId()!= userId){
            throw new RuntimeException("您没有删除权限!");
        }
        removeById(id);
    }


}
